package com.goodving.guli.bt.profile.scale;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

import com.goodving.guli.bt.BLEService;
import com.goodving.guli.bt.model.C3908f;
import com.goodving.guli.bt.model.C3910h;
import com.goodving.guli.bt.weight.UserInfo;

/**
 * Created by john on 2015/11/25.
 */
public class XMBLEManager {

    private static String f19458a;
    private static C3863r f19459b;
    private static ServiceConnection f19460c;

    static {
        final class C3845b implements ServiceConnection {
            C3845b() {
            }

            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                if (iBinder instanceof BLEService.C3864q) {
                    XMBLEManager.f19459b = (C3863r) iBinder;
                }
            }

            public void onServiceDisconnected(ComponentName componentName) {
                XMBLEManager.f19459b = null;
            }
        }
        f19458a = "BLEManager";
        f19459b = null;
        f19460c = new C3845b();

    }



    public static C3942j m25149a() {
        return f19459b != null ? f19459b.m25211b() : null;
    }

    public static void m25150a(BluetoothDevice bluetoothDevice, boolean z) {
        if (f19459b != null) {
            f19459b.m25208a(bluetoothDevice, z);
        }
    }

    public static void m25151a(BluetoothDevice bluetoothDevice, boolean z, UserInfo userInfo) {
        if (f19459b != null) {
            f19459b.m25209a(bluetoothDevice, z, userInfo);
        }
    }

    public static void m25152a(Context context, String str, com.goodving.guli.bt.model.UserInfo userInfo) {
        XMBLEManager.startBleServiceForDevice(context, str, userInfo);
    }

    public static void m25153a(C0638c c0638c, long j) {
        if (f19459b != null) {
            f19459b.m25210a(c0638c, j);
        }
    }

    @TargetApi(18)
    public static boolean m25154a(Context context) {
        boolean hasSystemFeature = context.getPackageManager().hasSystemFeature("android.hardware.bluetooth_le");
        GuliLog.tracePrintInfo(f19458a, "isSupportBle:" + hasSystemFeature);
        return hasSystemFeature;
    }

    public static void m25155b() {
        if (f19459b != null) {
            f19459b.m25215f();
        }
    }

    public static void startBleServiceForDevice(Context context, String str, com.goodving.guli.bt.model.UserInfo userInfo) { // m25156b
        Intent intent = new Intent(context, BLEService.class);
        if (str != null && userInfo != null && str != "") {
            intent.putExtra(BLEService.mBleMacAddr, str);
            intent.putExtra(BLEService.mBleUserInfo, userInfo);
        }
        context.startService(intent);
        if (f19459b == null) {
            context.bindService(intent, f19460c, Context.BIND_AUTO_CREATE);
        }
    }

    private static boolean m25157b(Context context) {
        boolean z;
        for (ActivityManager.RunningServiceInfo runningServiceInfo : ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningServices(Integer.MAX_VALUE)) {
            if (runningServiceInfo.service.getPackageName().equals(context.getPackageName()) && BLEService.class.getName().equals(runningServiceInfo.service.getClassName())) {
                z = true;
                break;
            }
        }
        z = false;
        GuliLog.tracePrintInfo(f19458a, "in isBLEServiceRunning:" + z);
        return z;
    }

    public static boolean m25158c() {
        if (f19459b != null) {
            C3942j b = f19459b.m25211b();
            if (b != null) {
                return b.m25615u();
            }
        }
        return false;
    }

    public static BluetoothDevice m25159d() {
        if (f19459b != null) {
            C3942j b = f19459b.m25211b();
            if (b != null) {
                return b.m25277f();
            }
        }
        return null;
    }

    public static C3908f m25160e() {
        if (f19459b != null) {
            C3942j b = f19459b.m25211b();
            if (b != null) {
                return b.m25574N();
            }
        }
        return null;
    }

    public static C3910h m25161f() {
        if (f19459b != null) {
            C3942j b = f19459b.m25211b();
            if (b != null) {
                return b.m25562B();
            }
        }
        return null;
    }

    public static C3910h m25162g() {
        if (f19459b != null) {
            C3942j b = f19459b.m25211b();
            if (b != null) {
                return b.j_();
            }
        }
        return null;
    }

    public static void m25163h() {
        if (f19459b != null) {
            f19459b.m25214e();
        }
    }

    public static WeightProfile m25164i() {
        return f19459b != null ? f19459b.m25213d() : null;
    }

    public static void m25165j() {
        if (f19459b != null) {
            f19459b.m25216g();
        }
    }

    public static HwConnStatus m25166k() {
        return f19459b != null ? f19459b.m25207a() : new HwConnStatus();
    }

    public static boolean m25167l() {
        return f19459b != null ? f19459b.m25212c() : false;
    }
}

